<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>raise_if_response_error (Ankoder::Browser)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/ankoder/browser.rb, line 13</span>
      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">raise_if_response_error</span>(<span class="ruby-identifier">res</span>)
        <span class="ruby-identifier">code</span> = <span class="ruby-identifier">res</span>.<span class="ruby-identifier">response</span>.<span class="ruby-identifier">code</span>.<span class="ruby-identifier">to_i</span>
        <span class="ruby-identifier">message</span> = <span class="ruby-identifier">res</span>.<span class="ruby-identifier">response</span>.<span class="ruby-identifier">message</span>
        <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">code</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^2/</span>
        
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">RequestError</span>, <span class="ruby-constant">Ankoder</span><span class="ruby-operator">::</span><span class="ruby-identifier">response</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>).<span class="ruby-identifier">content</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">code</span> <span class="ruby-operator">==</span> <span class="ruby-value">400</span>
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotAuthorized</span>, <span class="ruby-identifier">message</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">code</span> <span class="ruby-operator">==</span> <span class="ruby-value">401</span>
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">ResourceNotFound</span>, <span class="ruby-identifier">message</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">code</span> <span class="ruby-operator">==</span> <span class="ruby-value">404</span>
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">ServerError</span>, <span class="ruby-identifier">message</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">code</span> <span class="ruby-operator">==</span> <span class="ruby-value">500</span>
      <span class="ruby-keyword kw">end</span></pre>
</body>
</html>